/**
 * 实现fps统计
 * 创建者：Carburn Ashroom
 * 2024.1.4
 */

package Fps;

import java.util.Date;

public class FpsCalc implements FpsCalcConfig {     // FpsCalc类是一个帧率计算器

    private int frames = 0;
    private Date start = new Date();
    private String fps = "0";

    public void add() {     // 计入一帧
        if (++frames == INTERVAL) {
            Date end = new Date();
            long dist = end.getTime() - start.getTime();
            double cFps = frames * 1000. / dist;
            fps = String.format(PRECISION, cFps);
            start = end;
            frames = 0;
        }
    }

    public String getFps() {
        return fps;
    }

}
